package xyz.keyon.service.impl;

import xyz.keyon.bean.User;
import xyz.keyon.dao.IUserDao;
import xyz.keyon.dao.impl.UserDaoImpl;
import xyz.keyon.service.IUserService;

public class UserServiceImpl implements IUserService {
    IUserDao dao = new UserDaoImpl();
    @Override
    public User login(String username, String password) {
        return dao.findUserByUsernameAndPassword(username, password);
    }

    @Override
    public int register(String username, String password) {
        //如果该用户名已存在，返回-1
        if(dao.isExistUser(username)) {
            return -1;
        } else {
            //增加成功返回1，增加失败返回0
            if(dao.addUser(username,password)) {
                return 1;
            } else {
                return 0;
            }
        }
    }
}
